import Vue from 'vue'
import App from './App.vue'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import 'bootstrap/dist/css/bootstrap.min.css'

import quillEditor from 'vue-quill-editor'
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'

import axios from 'axios'
import VueAxios from 'vue-axios'
import Vuex from 'vuex'
import VueRouter from 'vue-router'

import Base64 from 'js-base64'
import router from './router.js'

Vue.use(ElementUI)
Vue.use(VueRouter)
Vue.use(VueAxios, axios)
Vue.use(Vuex)
Vue.use(quillEditor)
Vue.use(Base64)

Vue.config.productionTip = false

axios.defaults.withCredentials = true


var store = new Vuex.Store({
    state:{
        UID:JSON.parse(localStorage.getItem('UID')),
        username:JSON.parse(localStorage.getItem('username')),
        email:JSON.parse(localStorage.getItem('email')),
    },
    mutations:{
    }
})

router.beforeEach((to, from, next) => {
    
    if (to.matched.some(record => record.meta.requireAuth)) { // 判断该路由是否需要登录权限
        
            if (localStorage.username) { // 判断缓存里面是否有 username  //在登录的时候设置它的值
                window.console.log(localStorage.username)
                next();
            } else {
                alert("请先登录！")
                next({
                    path: '/',
                    query: {
                        redirect: to.fullPath
                    } // 将跳转的路由path作为参数，登录成功后跳转到该路由
                })
            }
        } else {
            next();
        }
});


new Vue({
    render: h => h(App),
    router,
    store,
}).$mount('#app')

